<template>
  <div>
    <Spin :spinning="loading" tip="Loading...">
      <div style="padding-top: 1rem;"></div>
    <!-- table -->
      <FormPanel ref="formPanel" :list="formList1" :cols="1" :formType="'add'" labelWidth="110" :isSubmitBtn="false" @formChange="formChangeHandle" />
      <BaseDialog :visible.sync="visibleDrawer" :title="'车辆编辑'" destroyOnClose :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}">
<!--        <vin @close="closeAdd" @save="saveAdd"></vin>-->
      </BaseDialog>
      <div style="padding-top: 1rem;"></div>
      <div
        :style="{
          position: 'absolute',
          left: 0,
          right: 0,
          zIndex: 9,
          borderTop: '1px solid #e9e9e9',
          padding: '10px 20px',
          background: '#fff',
          textAlign: 'right'
        }"
      >
        <multiuse-button type="primary" :click="EditDialog.bind()" :insertCar="insertCar">保 存</multiuse-button>
        <multiuse-button type="close" @click="closeDialog()">关 闭</multiuse-button>
      </div>
    </Spin>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
export default {
  mixins: [dictionary],
  props: {
    rowData: {
      type: Object,
      required: true
    },
    formData: {
      type: Object,
      required: true
    },
  },
  data() {
    return {
      loading: false,
      dataList1: [],
      visible: false,
      visibleDrawer: false,
      collapse: false,
      visibleAdd: false,
      infoId: null,
      type:'',
      saveData: null,
      flterValue: {}, //参数
      res: {}, //返回值
      fetchParams: {}, //ipa 接口
      insertCar: {},//添加的车辆信息
      formList1: this.createFormList1(),
    };
  },
  methods: {

    formChangeHandle(val) {
      console.log("formData=============================>"+this.formData)
      console.log(val);
      this.saveData = val;
      this.saveData.spId = this.rowData.spId;
    },
    //保存
    chooseOrderNo() {
      this.visibleDrawer = false;
    },
    closeAdd() {
      this.visibleDrawer = false;
      this.fetchParams = { ...this.fetchParams };
    },
   async saveAdd() {
      this.visibleDrawer = false;
      this.fetchParams = { ...this.fetchParams };
    },
    async EditDialog() {
      let [err, data] = await this.$refs.formPanel.GET_FORM_DATA();
      data.index=this.formData["index"];
      // let index = this.fromData.index
      // data = data.set("index",index);
      this.EditCar = data
      console.log("EditCar=============>",this.EditCar)
      if (err) return;
      if (data !== null) {
        this.loading = true;
        this.$emit('editCarSave',this.EditCar);
         return this.$notify.success({title: '提示信息', message: '修改成功'});
      }else {
        this.loading = false;
        // this.$notify.error({ title: '提示信息', message: res.errMsg || '保存失败!' });
        // this.closeDialog();
      }
    },
    //取消操作
    closeDialog(type) {
      if(type == 'refresh'){
        this.$emit('closeEdit');
      } else {
        this.$emit('close', { visibleAdd: false, data: this.insertCar, type: 'close' });
      }

    },
    add() {},
    createFormList1() {
      return [

        {
          type: 'SELECT',
          label: '备件类型',
          fieldName: 'partType',
          readonly: true, // 只读
          disabled: true, //置灰
          placeholder: '请选择配件类型...',
          initialValue: this.formData['partType'],
          itemList: this.createDictList('5509'),
          rules: [{required: true, message: '请选择配件类型...', trigger: 'change'}]
        },
        {
          type: 'INPUT',
          label: '保修期',
          fieldName: 'vpPeriod',
          initialValue: this.formData['vpPeriod'],
          placeholder: '请输入保修期...',
          rules: [
            {
              required: true,
              validator: (rule, value, callback) => {
                if (!value) {
                  return callback(new Error('请输入保修期...'));
                }
                if (!Number.isInteger(Number(value))) {
                  return callback(new Error('请输入数字值...'));
                }
                if(value.length > 10){
                  return callback(new Error('请输入10位以内的数值'));
                }
                callback();
              },
              trigger: ['blur', 'change'],
            },
          ],
          unitRender: () => {
            return <span>(月)</span>;
          },
        },
        {
          type: 'INPUT',
          label: '保修里程',
          fieldName: 'vpMile',
          placeholder: '请输入保修里程...',
          initialValue: this.formData['vpMile'],
          rules: [
            {
              required: true,
              validator: (rule, value, callback) => {
                if (!value) {
                  return callback(new Error('请输入保修里程...'));
                }
                if (!Number.isInteger(Number(value))) {
                  return callback(new Error('请输入数字值...'));
                }
                if(value.length > 10){
                  return callback(new Error('请输入10位以内的数值'));
                }
                callback();
              },
              trigger: ['blur', 'change'],
            },
          ],
          unitRender: () => {
            return <span>(KM)</span>;
          },
        },
      ];
    }
  }
};
</script>

<style lang="less" scoped></style>
